<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/home/include/init_home.jsp" %>
<%@ page import="com.qbooks.board.*" %>
<%
	String board_id 	= StringUtil.nvl(request.getParameter("board_id"));
	String word_id		= StringUtil.nvl(request.getParameter("word_id"));

	HashMap param = new HashMap();
	param.put("board_id",	board_id);
	param.put("word_id", 	word_id);


	BoardDAO boardDAO 		= new BoardDAO();
	HashList wordInfo		= boardDAO.selectWordInfo(param);

	boolean bEditor			= "Y".equals(wordInfo.get("editor_yn",0)) ? true : false;
	boolean bSecret			= "Y".equals(wordInfo.get("secret_yn",0)) ? true : false;


	String writeAuth		= wordInfo.get("write_auth",0);

	if (isAdmin == false) {
		if ("A".equals(writeAuth)) {
			request.setAttribute("exception", new Exception("글쓰기 권한이 없습니다."));
			RequestDispatcher disp = request.getRequestDispatcher("/common/error_page.jsp");
			disp.forward(request, response);
		}
		else if ("M".equals(writeAuth)) {
			if (isLogin == false) {
				request.setAttribute("exception", new Exception("글쓰기 권한이 없습니다."));
				RequestDispatcher disp = request.getRequestDispatcher("/common/error_page.jsp");
				disp.forward(request, response);
			}
		}
	}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title><%= HOME_NAME %></title>
	<%@ include file="/home/include/cssnjs.jsp"  %>
<%	if (bEditor) { %>
	<script type="text/javascript" src="/SE2.3.1.O9858/js/HuskyEZCreator.js" charset="utf-8"></script>
<%	} %>

	<script type="text/javascript">
	var oEditors = [];
	var bEditor	= <%= bEditor %>;

	$(document).ready(function() {
		if (bEditor) {
			cfInitSE("content_<%=board_id%>");
		}
	});

	function fnSave() {
		if (document.boardForm.subject.value == "") {
			alert("제목을 입력하세요");
			document.boardForm.subject.focus();
			return false;
		}
		if (bEditor) {
			oEditors.getById["content_<%=board_id%>"].exec("UPDATE_CONTENTS_FIELD", []);
		}
		document.boardForm.submit();
	}


	</script>
</head>

<body>
<div id="wrap">

		<h3><%= wordInfo.get("board_name",0) %></h3>

		<form name="boardForm" action="./wordUpdate.do" method="post" <%	if (bEditor) { %>enctype="multipart/form-data"<%} %>>
        <input type="hidden" name="board_id" value="<%= board_id %>"/>
        <input type="hidden" name="word_id" value="<%= word_id %>"/>
		<div>제목:<input type="text" name="subject" style="width:610px;" class="input2" value="<%= wordInfo.get("subject",0) %>"/></div>
	<%	if (isAdmin) { %>
			<div>작성자:<input type="text" name="author_name" value="<%= wordInfo.get("author_name",0) %>"/></div>
	<%	} else if (isLogin) { %>
			<div>작성자:<%= wordInfo.get("author_name",0) %><input type="hidden" name="author_name" value="<%= wordInfo.get("author_name",0) %>"/></div>
	<%	} else { %>
			<div>작성자:<input type="text" name="author_name" value="<%= wordInfo.get("author_name",0) %>"/></div>
			<div>비밀번호:<input type="text" name="password" value="<%= wordInfo.get("password",0) %>"/></div>
	<%	} %>

	<%	if (bSecret) { %>
			<div><input type="checkbox" name="secret_yn" value="Y" <%= StringUtil.checked("Y", wordInfo.get("secret_yn",0)) %>/>비밀글</div>
	<%	} %>
		<div><textarea name="content_<%=board_id%>" id="content_<%=board_id%>" style="width:100%; height:400px;" ><%= wordInfo.get("content",0) %></textarea></div>

		<div style="text-align:center">
			<a href="#nohref" onclick="history.back()"><img src="../images/sub/complete.gif" alt="취소" border="0"/></a>
			<a href="#nohref" onclick="fnSave()"><img src="../images/sub/complete.gif" alt="확인" border="0"/></a>
		</div>
		</form>

</div>
</body>
</html>

